//
//  YHBaseTabBarController.m
//  TestYoho
//
//  Created by YiDarren on 17/1/19.
//  Copyright © 2017年 YiDarren. All rights reserved.
//

#import "YHBaseTabBarController.h"
#import "MBProgressHUD+JDragon.h"
#import "MBProgressHUD.h"

#import "LoginViewController.h"


@interface YHBaseTabBarController ()<UITabBarControllerDelegate>

@end

@implementation YHBaseTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    //注意设置自己为委托人
    self.delegate = self;
    [self configureApp];
    
}

- (void)configureApp {

    self.tabBar.translucent = YES;
//    [self.tabBar setBarTintColor:[UIColor whiteColor]];
#pragma mark - 下面两行代码作用同上
//    [UITabBar appearance].translucent = NO;
//    [[UITabBar appearance] setBarTintColor:[UIColor redColor]];
    
}


- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController NS_AVAILABLE_IOS(3_0) {
    
    UINavigationController *nav = (UINavigationController *)viewController;
    
    if([[[nav viewControllers] firstObject] isKindOfClass:NSClassFromString(@"MineViewController")]) {
        
        [MBProgressHUD showWarnMessage:@"先登录方可进入我的UI"];
        
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        
        LoginViewController *loginVC = [storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
        
        [self presentViewController:loginVC animated:YES completion:^{
            
        }];
        
        return NO;
    }
    
    
    return YES;
    
}
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    
    UINavigationController *nav = (UINavigationController*)viewController;
    
    if ([[[nav viewControllers] firstObject] isKindOfClass:NSClassFromString(@"GoAroundViewController")]) {
        
        NSLog(@"%s", __func__);
    }
    
}
- (void)tabBarController:(UITabBarController *)tabBarController didEndCustomizingViewControllers:(NSArray<__kindof UIViewController *> *)viewControllers changed:(BOOL)changed __TVOS_PROHIBITED {
    
    
}

- (UIInterfaceOrientation)tabBarControllerPreferredInterfaceOrientationForPresentation:(UITabBarController *)tabBarController NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED {
    
    return UIInterfaceOrientationPortrait;
}

- (nullable id <UIViewControllerInteractiveTransitioning>)tabBarController:(UITabBarController *)tabBarController
                               interactionControllerForAnimationController: (id <UIViewControllerAnimatedTransitioning>)animationController NS_AVAILABLE_IOS(7_0) {
    
    return nil;
}

- (nullable id <UIViewControllerAnimatedTransitioning>)tabBarController:(UITabBarController *)tabBarController
                     animationControllerForTransitionFromViewController:(UIViewController *)fromVC
                                                       toViewController:(UIViewController *)toVC  NS_AVAILABLE_IOS(7_0) {
    
    
    return nil;
}

//未起作用
-(UIStatusBarStyle)preferredStatusBarStyle {
    
    return UIStatusBarStyleDefault;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
